<template>
    <div class="index-lists">
        <el-card class="!border-none mt-4" shadow="never">
            <div>
                <el-button v-perms="['ruleconfiguration:add']" type="primary" @click="handleAdd()">
                    <template #icon>
                        <icon name="el-icon-Plus" />
                    </template>
                    添加配置
                </el-button>
            </div>
            <el-table class="mt-4" size="large" v-loading="pager.loading" :data="pager.lists">
                <el-table-column type="selection" width="55" />
                <el-table-column label="ID" prop="id" min-width="50" />
                <el-table-column label="规则类型" prop="ruleTyp" min-width="100" />
                <el-table-column label="通知书类型" prop="typeNotification" min-width="100" />
                <el-table-column label="处理事项类型" prop="transactionType" min-width="100" />
                <el-table-column label="处理事项状态" prop="transactionStatus" min-width="100" />
                <el-table-column label="邮件标签类型" prop="mailLabelType" min-width="100" />
                <el-table-column label="申请人" prop="applicant" min-width="100" />
                <el-table-column label="主题" prop="theme" min-width="100" />
                <el-table-column label="收件人" prop="recipients" min-width="100" />
                <el-table-column label="抄送" prop="copy" min-width="100" />
                <el-table-column label="密送" prop="blindCarbonCopy" min-width="100" />
                <el-table-column label="操作" width="120" fixed="right">
                    <template #default="{ row }">
                        <el-button
                            v-perms="['ruleconfiguration:edit']"
                            type="primary"
                            link
                            @click="handleEdit(row)"
                        >
                            编辑
                        </el-button>
                        <el-button
                            v-perms="['ruleconfiguration:del']"
                            type="danger"
                            link
                            @click="handleDelete(row.id)"
                        >
                            删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
        <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
    </div>
</template>
<script lang="ts" setup name="ruleconfiguration">
import { ruleconfigurationDelete, ruleconfigurationLists } from '@/api/ruleconfiguration'
import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
const queryParams = reactive({
    ruleTyp: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: ruleconfigurationLists,
    params: queryParams
})

const handleAdd = async () => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('add')
}

const handleEdit = async (data: any) => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('edit')
    editRef.value?.getDetail(data)
}

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await ruleconfigurationDelete({ id })
    feedback.msgSuccess('删除成功')
    getLists()
}

getLists()
</script>
